package com.example.javaproject.datastructure.array;

/**
 * Description:
 * <br/>Author:  tianjinyong
 * <br/>Date:    2020/6/30 1:42 PM
 */
public class ArrayListTest {

    public static void main(String[] args) {
        mockArrayListRemoveByIndex();
    }

    /**
     * 模拟ArrayList.remove(int index)
     */
    public static void mockArrayListRemoveByIndex() {
        Integer[] src = {1, 2, 3, 4, 5};
        int index = 1;
        int length = src.length - index - 1;

        System.arraycopy(src, index + 1, src, index, length);
        System.out.println("copy后数据--");
        for (Integer item : src) {
            System.out.print(item + ",");
        }

        int size = src.length;
        src[--size] = null;

        System.out.println("\n置空后的数据--");
        for (Integer item : src) {
            System.out.print(item + ",");
        }

    }

    private Thread testThread;
    private void testThread() {
        testThread = new Thread(() -> {
            while (!testThread.isInterrupted()) {
                try {
                    doSomething1();
                    doSomething2();
                } catch (Exception e) {
                    if(e instanceof InterruptedException) {
                        Thread.currentThread().interrupt();
                    }
                }
            }
        });

        // 调用interrupter()方法中断线程
        testThread.interrupt();
    }

    private void doSomething2() {}

    private void doSomething1() {}
}
